class FibIterator extends Iterator[Int] {

  private var prev1 = 1;
  private var prev2 = 0;

  def hasNext = true

  def next = {
    val orig_prev2 = this.prev2
    val fib = this.prev1 + this.prev2

    this.prev2 = this.prev1
    this.prev1 = fib

    orig_prev2
  }

}


object fibonacci {

  def main(args: Array[String]) = {
    val fib = new FibIterator
    for (x <- 0 to args(0).toInt) print(fib.next + " ")
      println("...")
  }
}
